package com.QiLin.controller;

import com.QiLin.domain.User;
import com.QiLin.service.LinService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@Controller  //让中央调度器把请求交给此类处理
public class login {
    @Resource
    private LinService linService;  //注入bean，service

    @RequestMapping("/enter.do")
    public String enter(User usera, HttpSession session){
        boolean us= linService.enterService(usera,session);
        if(us){
            return "/Mailbox";
        }else{
            return "index";
        }
    }

    @RequestMapping("/Signin.do")
    public String signin(User usera){

        if(linService.DetectionRepetition(usera.getQname(),usera.getUser())){
            if(linService.LengthDetection(usera.getUser(),usera.getPassword())){
                linService.signinService(usera);
                return "/index";
            }else {
                return "/signin";
            }

        }else{
            return "/signin";
        }

    }

    @RequestMapping("/GetData.do")
    @ResponseBody
    public User GetData(HttpSession session){
        return linService.GetDataService(session);
    }


}